package com.my.hp_hr.dao;

import com.my.hp_hr.entity.Leave;
import com.my.hp_hr.util.BaseDAO;

import java.util.List;

public class LeaveDao extends BaseDAO {

    public List<Leave> getNotAgreeList(int department_number, String status) throws Exception {
        //String sql = "select * from lea where department_number = ? && status=?";
        String sql = "select distinct l.id,l.employee_number,l.start_time,l.end_time,l.days,l.reason,l.type,l.manager,l.status,l.notes,e.name from lea l" +
                " inner join employee e on l.department_number = e.department_number\n" +
                "where l.department_number = ? && l.status=? group by l.id";
        Object[] obj = {department_number,status};
        List<Leave> list = getList(sql, new Leave(), obj);
        return list;
    }

    public List<Leave> getAgreeList(int department_number, String status) throws Exception {
        String sql = "select distinct l.id,l.employee_number,l.start_time,l.end_time,l.days,l.reason,l.type,l.manager,l.status,l.notes,e.name from lea l" +
                " inner join employee e on l.department_number = e.department_number\n" +
                "where l.department_number = ? && l.status=? group by l.id";
        Object[] obj = {department_number,status};
        List<Leave> list = getList(sql, new Leave(), obj);
        return list;
    }

    public List<Leave> getAllList(int department_number) throws Exception {
        String sql = "select distinct l.id,l.employee_number,l.start_time,l.end_time,l.days,l.reason,l.type,l.manager,l.status,l.notes,e.name from lea l" +
                " inner join employee e on l.department_number = e.department_number\n" +
                "where l.department_number = ? group by l.id";
        Object[] obj = {department_number};
        List<Leave> list = getList(sql, new Leave(), obj);
        return list;
    }

    public Leave getLeaveList(String id) throws Exception {
        //String sql = "select * from lea where id = ? ";
        String sql = "select distinct l.id,l.employee_number,l.start_time,l.end_time,l.days,l.reason,l.type,l.manager,l.status,l.notes,e.name from lea l" +
                " inner join employee e on l.department_number = e.department_number\n" +
                "where l.id = ? group by l.id";
        Object[] obj ={id};
        Leave leave = getOne(sql, new Leave(), obj);
        return leave;
    }

    public void updateLeave(String id,String status) throws Exception {
        String sql = "update lea set status =? where id = ?";
        Object[] obj = {status,id};
        addOrupdOrdel(sql,obj);
    }
}
